<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script type="text/javascript" src="/${initParam.context_root }/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="/${initParam.context_root }/jquery-ui-1.8.21.custom.min.js"></script>
<link type="text/css" href="/${initParam.context_root }/css/smoothness/jquery-ui-1.8.21.custom.css" rel="stylesheet"></link>
<script type="text/javascript">
$(document).ready(function(){
//  	$("input[value='수정']").click(modify(i));
});
function modify(i){
	var flag = window.confirm("수정하시겠습니까?");
	if(flag){
 		var url = "/${initParam.context_root}/saleModifyForm.do?saleNo="+i;
		$("#saleModify").attr({"action":url,"method":"post"}).submit();
	}
	else{
		return false;
	}
}
function remove(i){
	var flag = window.confirm("삭제시 신용도(-1)와 마일리지(-100)가 삭감됩니다.\n정말 삭제하시겠습니까?");
	if(flag){
 		var url = "/${initParam.context_root}/saleDelete.do?saleNo="+i;
		$("#saleModify").attr({"action":url,"method":"post"}).submit();
	}
	else{
		return false;
	}
}
</script>
<h2>구매 상품 리스트</h2>
<table border=2 align="right">
<tr><td>
<c:choose>
<c:when test="${not empty sessionScope.memberDTO || not empty sessionScope.companyDTO || not empty sessionScope.adminDTO  }">
<input type="button" value="구매내역 등록하기"  onclick="location.href='/${initParam.context_root}/saleSearch.do'" >
</c:when>
<c:otherwise>
	<font color="red" ><b>로그인을 먼저 해주세요.</b></font>
</c:otherwise>
</c:choose>
</td></tr>
</table><p>
<table border=2 width=900px>
<tr>
		<th rowspan="2" width="5%" bgcolor="lightgray">no</th>
		<th rowspan="2" width="5%" bgcolor="lightgray">지역</th>
		<th rowspan="2" width="13%" bgcolor="lightgray">이미지</th>
		<th bgcolor="lightgray">구매사이트명</th>
		<th bgcolor="lightgray">상품가격</th>
		<th rowspan="2" width="7%" bgcolor="lightgray">구매량</th>
		<th rowspan="2" width="10%" bgcolor="lightgray">구매일</th>
		<th rowspan="2" width="20%" bgcolor="lightgray">메모</th>
		<th bgcolor="lightgray">수정</th>
	</tr>
	<tr>
		<th width="15%" bgcolor="lightgray">상품명</th>
		<th width="10%" bgcolor="lightgray">쿠폰가격</th>
		<th width="5%"bgcolor="lightgray">삭제</th>
	</tr>
	<c:choose>
	<c:when test="${empty requestScope.listSaleDTO.list  }">
		<tr>
		<td colspan="9"><font color=red>구매내역이 없습니다. </font> 
		</td>
		</tr>
	</c:when>
	<c:when test="${not empty requestScope.listSaleDTO }">
	<c:forEach items="${requestScope.listSaleDTO.list }" var="saleDTO" varStatus="i">
		<tr>
			<td rowspan="2">${i.count }</td>
			<td rowspan="2" >${saleDTO.location }</td>
			<td rowspan="2" >
				<c:if test="${not empty saleDTO.productImage }">
					<img src="/${initParam.context_root }/upfile/${saleDTO.productImage}" width="80" height="50">
				</c:if>
			</td>
			<td >${saleDTO.siteName }</td>
			<td><strike>${saleDTO.productPrice }</strike>원</td>
			<td rowspan="2" >${saleDTO.quantity }개</td>
			<td rowspan="2" >${saleDTO.saleDate }</td>
			<td rowspan="2" >${saleDTO.memo }</td>
			<td><form id="saleModify"><input type="button" value="수정" onclick="modify(${saleDTO.saleNo})"></form></td>
		</tr>
		<tr>
			<td >${saleDTO.productName }</td>
			<td >${saleDTO.reducedPrice } 원</td>
			<td><form><input type="button" value="삭제" onclick="remove(${saleDTO.saleNo})"></form></td>
		</tr>
	</c:forEach>
	</c:when>
	<c:otherwise>
		<tr>
		<td colspan="9"> 로그인을 먼저 해주세요. 
		</td>
		</tr>
	</c:otherwise>
	</c:choose>
</table>
<table cellpadding=12	border=2 bgcolor=#f5fffa cellspacing=0 width= 200>
		<tr><td>
		<c:choose >
		<c:when test="${ requestScope.listSaleDTO.pageDTO.previousPageGroup }"> 
			<a href="/${initParam.context_root }/selectSaleListByPage.do?page=${requestScope.listSaleDTO.pageDTO.currentPage -1}">◀</a>
		</c:when>
		<c:otherwise>◀</c:otherwise>
		</c:choose>
		<c:forEach begin="${requestScope.listSaleDTO.pageDTO.startPageOfPageGroup }" end="${requestScope.listSaleDTO.pageDTO.endPageOfPageGroup }" step="1" var="i">
			&nbsp;<font color=orange><B><a href="/${initParam.context_root }/selectSaleListByPage.do?page=${i }">${i }</a></B></font>&nbsp;&nbsp;	
		</c:forEach>
		<c:choose >
		<c:when test="${ requestScope.listSaleDTO.pageDTO.nextPageGroup }"> 
			<a href="/${initParam.context_root }/selectSaleListByPage.do?page=${requestScope.listSaleDTO.pageDTO.currentPage +1 }">▶</a>
		</c:when>
		<c:otherwise>▶</c:otherwise>
		</c:choose>
		</td></tr>
</table>

<table border=2 align="right">
<tr><td>
<c:choose>
	<c:when test="${not empty sessionScope.memberDTO || not empty sessionScope.companyDTO || not empty sessionScope.adminDTO  }">
		<input type="button" value="구매내역 등록하기"  onclick="location.href='/${initParam.context_root}/saleSearch.do'" >
	</c:when>
	<c:otherwise>
		<font color="red" ><b>로그인을 먼저 해 주세요.</b></font>
	</c:otherwise>
</c:choose>
</td></tr>
</table><p>
